/*
 * 〈描述〉
 *
 * @author chenxing
 * @since 版本号
 */

package com.maorioi.failureanalyzer.component;

import com.maorioi.failureanalyzer.model.CompileFailure;
import com.maorioi.failureanalyzer.model.Failure;
import com.maorioi.failureanalyzer.model.MessageWrapper;
import com.maorioi.failureanalyzer.model.StartupFailure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉
 *
 * <p>〈功能详细描述〉
 *
 * @author chenxing
 * @since 版本号
 */
@RestController
public class FaController {

    @Autowired
    private FaService faService;

    @PostMapping("notifyCompileFailure")
    public MessageWrapper<Failure> notifyCompileFailure(@Valid @RequestBody CompileFailure compileFailure) {
        return new MessageWrapper(true, null, faService.notifyCompileFailure(compileFailure));
    }

    @PostMapping("notifyStartupFailure")
    public MessageWrapper<Failure> notifyStartupFailure(@Valid @RequestBody StartupFailure startupFailure) {
        return new MessageWrapper(true, null, faService.notifyStartupFailure(startupFailure));
    }

    @PostMapping("alterProjectWatcher")
    public MessageWrapper<Void> alterProjectWatcher(@RequestBody Map<String,String> watchers) {
        faService.alterProjectWatcher(watchers);
        return new MessageWrapper(true, null, null);
    }
    @GetMapping("findLatestCommit")
    public MessageWrapper<List> listLatestCommit(@RequestParam("project") String project,
                                                 @RequestParam("branch") String branch,
                                                 @RequestParam("filePath") String filePath) {
        return new MessageWrapper(true, null, faService.listLatestCommit(project,branch,filePath));
    }
    
}
